package com.yit.cn;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by zhangyanfei on 2019/4/21.
 *
 * @author zhangyanfei
 * @date 2019/04/21
 */
public class PlanManager {

    private static final SchedulingContext schedulingContext;

    private static final ArrayList<AbstractPlan> abstractPlans;

    static {
        schedulingContext = new SchedulingContext();

        PlanA planA = new PlanA(schedulingContext);
        PlanB planB = new PlanB(schedulingContext);
        PlanC planC = new PlanC(schedulingContext);
        PlanD planD = new PlanD(schedulingContext);

        abstractPlans = new ArrayList<AbstractPlan>();

        abstractPlans.add(planA);
        abstractPlans.add(planB);

        abstractPlans.add(planC);

        abstractPlans.add(planD);

    }

    /**
     * 起飞
     *
     * @param date
     */
    public String fly(Date date) {
        StringBuilder content = new StringBuilder();
        schedulingContext.setDate(date);
        schedulingContext.isFly = true;
        for (AbstractPlan abstractPlan : abstractPlans) {
            if (abstractPlan.condition()) {
                if ("testyA".equalsIgnoreCase(abstractPlan.getPilot().getTag())) {
                    schedulingContext.grandTotalDaysOfA += 1;
                }

                if (schedulingContext.grandTotalDaysOfA > SchedulingContext.threshold
                    && schedulingContext.restOfA > 10) {
                    // A加班超过11天 并且已经休息了10天 则重置
                    schedulingContext.grandTotalDaysOfA = 0;
                    schedulingContext.restOfA = 0;
                }

                /**
                 * 获取飞行员信息
                 */
                content.append("飞行员代号：").append(abstractPlan.getPilot().getTag()).append("；");
                /**
                 * 获取油耗
                 */
                content.append(abstractPlan.getSFCofDay());
                /**
                 * 获取飞行时间
                 */
                content.append(abstractPlan.getElapsedTime());
            }

        }

        return content.toString();
    }
}
